import zara.Role
import zara.Website
import zara.User
class BootStrap {
    def authenticateService
    def init = { servletContext ->

        ['ROLE_USER':'普通用户',
        'ROLE_ADMIN':'系统管理员'].each{ entry ->
         new Role(authority:entry.key,
                        description:entry.value).save()
        }

        if (!User.findByUsername('admin')) {
            def person = new User(username: 'admin' ,email:'halleluja@126.com', enabled : true)
            person.passwd = authenticateService.encodePassword('1qazxsw2')
            person.save()
            Role.findByAuthority("ROLE_ADMIN").addToPeople(person) 
        }

        def websites = Website.list()
        def  results = []
        websites.each{
            results.add(it.id)
        }
        servletContext['websiteList'] = results
    }
    def destroy = {
    }
}
